﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.d00_zjs_zcMenu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void d00_zjs_zc_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            d00_zjs_zcMgr mgr = new d00_zjs_zcMgr();
            e.Total = int.Parse(mgr.GetRecordCount_d00_zjs_zc(e.Parameters[d00_zjs_zc_Filter.ParamPrefix]));
            IList<d00_zjs_zc> list = mgr.FindAllByPage_d00_zjs_zc(e.Start.ToString(), e.Limit.ToString(), e.Parameters[d00_zjs_zc_Filter.ParamPrefix]);
            d00_zjs_zc_MainStore.DataSource = list;
            d00_zjs_zc_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            d00_zjs_zcMgr mgr = new d00_zjs_zcMgr();
            RowSelectionModel sm = d00_zjs_zc_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                d00_zjs_zc _d00_zjs_zc = new d00_zjs_zc();
                _d00_zjs_zc.dzbm = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_d00_zjs_zc(_d00_zjs_zc))
                {
                    log.Debug("d00_zjs_zc中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            d00_zjs_zc_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            d00_zjs_zcMgr mgr = new d00_zjs_zcMgr();
            d00_zjs_zc _d00_zjs_zc = new d00_zjs_zc();
            if (Hid.Text.Length > 0)
                _d00_zjs_zc = mgr.FindById_d00_zjs_zc(int.Parse(Hid.Text));
            
			_d00_zjs_zc.rbh = Txtrbh.Text.Trim();
			_d00_zjs_zc.xh = Txtxh.Text.Trim();
			_d00_zjs_zc.hzxm = Txthzxm.Text.Trim();
			_d00_zjs_zc.xm = Txtxm.Text.Trim();
			_d00_zjs_zc.hzgx = Txthzgx.Text.Trim();
			_d00_zjs_zc.xb = Txtxb.Text.Trim();
			_d00_zjs_zc.csrq = Txtcsrq.Text.Trim();
			_d00_zjs_zc.hyzk = Txthyzk.Text.Trim();
			_d00_zjs_zc.mz = Txtmz.Text.Trim();
			_d00_zjs_zc.sfzh = Txtsfzh.Text.Trim();
			_d00_zjs_zc.csd = Txtcsd.Text.Trim();
			_d00_zjs_zc.lsdh = Txtlsdh.Text.Trim();
			_d00_zjs_zc.jtrs = int.Parse(TxtNumjtrs.Text.Trim());
			_d00_zjs_zc.cjrs = int.Parse(TxtNumcjrs.Text.Trim());
			_d00_zjs_zc.tsrs = int.Parse(TxtNumtsrs.Text.Trim());
			_d00_zjs_zc.hsx = Txthsx.Text.Trim();
			_d00_zjs_zc.jfje = Txtjfje.Text.Trim();
			_d00_zjs_zc.jfsj = Txtjfsj.Text.Trim();
			_d00_zjs_zc.fphm = Txtfphm.Text.Trim();
			_d00_zjs_zc.sfy = Txtsfy.Text.Trim();
			_d00_zjs_zc.hbh = Txthbh.Text.Trim();
			_d00_zjs_zc.bz3 = Txtbz3.Text.Trim();
			_d00_zjs_zc.bz4 = Txtbz4.Text.Trim();
			_d00_zjs_zc.bz1 = Txtbz1.Text.Trim();
			_d00_zjs_zc.bz2 = Txtbz2.Text.Trim();
			_d00_zjs_zc.id = int.Parse(TxtNumid.Text.Trim());
			_d00_zjs_zc.jgdm = Txtjgdm.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_d00_zjs_zc(_d00_zjs_zc);
            else
                isok = mgr.Add_d00_zjs_zc(_d00_zjs_zc);
            if (isok)
            {
                d00_zjs_zc_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("d00_zjs_zc中执行了保存（插入或修改），并成功");
                d00_zjs_zc_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}